<template>
	<view class="container">
		<block v-if="listData.length > 0">
			<u-cell-group>
				<block v-for="(item, index) in listData" :key="index">
					<u-cell>
						<view slot="title">
							<view>
								<text class="grey_color size28">跟进人：</text>
								{{ item.member.name }}
							</view>
							<view>
								<text class="grey_color size28">跟进时间：</text>
								{{ $u.timeFormat(item.next_time * 1000, 'yyyy年mm月dd日 hh时MM分ss秒') }}
							</view>
							<view>
								<text class="grey_color size28">跟进类型：</text>
								{{ item.type }}
							</view>
							<view>
								<text class="grey_color size28">意向跟进：</text>
								{{ item.type_cate }}
							</view>
							<view>
								<text class="grey_color size28">客情维系：</text>
								{{ item.type_cate1 }}
							</view>
							<view>
								<text class="grey_color size28">售后回访：</text>
								{{ item.type_cate2 }}
							</view>
							<view>
								<text class="grey_color size28">投诉跟进：</text>
								{{ item.type_cate3 }}
							</view>
							<view>
								<text class="grey_color size28">保养邀约：</text>
								{{ item.type_cate4 }}
							</view>
							<view>
								<text class="grey_color size28">跟进方式：</text>
								{{ item.way }}
							</view>
							<view>
								{{ item.description }}
							</view>
						</view>
						<view slot="label">
							<view class="btn">
								<view class="success_btn font28" v-if="!item.is_follow" @click="sendFollow(item, index)">已跟进</view>
							</view>
						</view>
					</u-cell>
				</block>
			</u-cell-group>
		</block>
		<block v-else>
			<view class="all_empty">
				<u-empty mode="data" text="跟进列表为空"></u-empty>
			</view>
		</block>
		<u-loadmore v-if="listData.length > searchForm.limit" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			searchForm: {
				limit: 10,
				page: 1
			},
			listData: [],
			status: 'loadmore',
			loadingText: '努力加载中',
			loadmoreText: '轻轻上拉',
			nomoreText: '实在没有了'
		};
	},
	onLoad() {
		this.$initConfig().then((_) => {
			this.getInfo();
		});
	},
	onReachBottom() {
		if (this.status != 'nomore') {
			this.searchForm.page++;
			this.getInfo(true);
		}
	},
	methods: {
		sendFollow(item, index) {
			let _this = this;
			uni.showModal({
				title: '确定已跟进了吗?',
				showCancel: true,
				success(btn) {
					if (btn.confirm) {
						_this
							.$http('follow/setFollowByStatus', {
								id: item.id
							})
							.then((res) => {
								if (res.code) {
									_this.$u.toast('操作成功');
									_this.listData[index]['is_follow'] = 1;
								}
							});
					}
				}
			});
		},
		getInfo(is_add = false) {
			let _this = this;
			this.status = 'loading';
			_this
				.$http('follow/getFollowByList', {
					...this.searchForm
				})
				.then((res) => {
					if (res.code) {
						if (is_add) {
							_this.listData = _this.listData.concat(res.data.data);
						} else {
							_this.listData = res.data.data;
						}
						if (_this.listData.length >= res.data.total) {
							this.status = 'nomore';
						} else {
							this.status = 'loadmore';
						}
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.btn {
	display: flex;
	flex-direction: row;
	justify-content: flex-end;
}
.success_btn {
	background: $uni-color-warning;
	color: #fff;
	width: fit-content;
	padding: 5rpx 20rpx;
	border-radius: 10rpx;
}
</style>
